package imagekeeper.data.mapping;

import java.util.ArrayList;
import java.sql.ResultSet;
import java.sql.SQLException;
import imagekeeper.dmi.Image;
import imagekeeper.dmi.User;


public class ImageMapper {
    public final static String TableName = "image";
    public final static String ColumnId = "id";
    public final static String ColumnTitle = "title";
    public final static String ColumnDescription = "description";
    public final static String ColumnOwnerId = "owner_id";
    public final static String ColumnPrivacy = "privacy";
    public final static String ColumnUploadedTime = "uploaded_time";
    public final static String ColumnLastAccessTime = "last_access_time";
    public final static String ColumnViews = "views";
    public final static String ColumnTotalUserMark = "total_user_mark";
    public final static String ColumnUserMarkCounter = "user_mark_counter";
    public final static String ColumnUrl = "url";
    public final static String ColumnRemovingLink = "removing_link";
    
    public final static String SpCreateImage = "create_image";
    public final static String SpRemoveImage = "remove_image";
    public final static String SpRemoveImageByLink = "remove_image_by_link";
    public final static String SpUpdateImage = "update_image";
    public final static String SpSelectImage = "select_image";
    public final static String SpSelectImageByUrl = "select_image_by_url";
    
    public static ArrayList<Image> getImages(ResultSet rs) throws SQLException {
        ArrayList<Image> result = new ArrayList<Image>();
        Image img = null;
        User imgOwner = null;
        while (rs.next()) {
            img = new Image(rs.getInt(ColumnId), rs.getString(ColumnTitle), rs.getString(ColumnDescription),
                            rs.getString(ColumnUrl), rs.getString(ColumnRemovingLink), imgOwner,
                            rs.getTimestamp(ColumnUploadedTime), rs.getTimestamp(ColumnLastAccessTime),
                            rs.getInt(ColumnViews), rs.getBoolean(ColumnPrivacy), 
                            rs.getInt(ColumnTotalUserMark), rs.getInt(ColumnUserMarkCounter));
            result.add(img);
        }
        return result;
    }
}
